#include "widget.h"
#include "ui_widget.h"
#include <QIcon>
#include <QDebug>
#include <QPushButton>
#include <QCursor>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //设置图标
    QIcon icon(":/gold.png");
    this->setWindowIcon(icon);

    //创建图对象
    QPixmap add_pixmap(":/add.png");
    QPixmap sub_pixmap(":/sub.png");
    //设置光标的大小
    add_pixmap=add_pixmap.scaled(25,25);
    sub_pixmap=sub_pixmap.scaled(25,25);
    //改变热点位置
    QCursor add_cursor(add_pixmap,10,10);
    QCursor sub_cursor(sub_pixmap,10,10);
    //设置光标
    ui->pushButton_clear->setCursor(add_pixmap);
    ui->pushButton_noclear->setCursor(sub_pixmap);

    //设置标签的字体
    QFont font;
    font.setFamily("微软雅黑");
    font.setPointSize(30);
    font.setBold(true);
    font.setItalic(true);
    //font.setUnderline(true);
    //font.setStrikeOut(true);
    ui->label->setFont(font);

    //设置按钮的提示说明
    ui->pushButton_clear->setToolTip("透明度增加");
    ui->pushButton_clear->setToolTipDuration(3000);
    ui->pushButton_noclear->setToolTip("透明度减少");
    ui->pushButton_noclear->setToolTipDuration(3000);

    //设置输入框的焦点
    ui->lineEdit_z->setFocusPolicy(Qt::TabFocus);
    ui->lineEdit_m->setFocusPolicy(Qt::ClickFocus);

    //设置标签的样式

}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clear_clicked()
{
    float opacity=windowOpacity();
    if(opacity>=1.0) return ;
    this->setWindowOpacity(opacity+0.1);
}

void Widget::on_pushButton_noclear_clicked()
{
    float opacity=windowOpacity();
    if(opacity<=0.0) return ;
    this->setWindowOpacity(opacity-0.1);
}

void Widget::on_pushButton_light_clicked()
{
    //设置窗口为白色
    this->setStyleSheet("background-color:#f0f0f0;");

    ui->lineEdit_m->setStyleSheet("background-color:#fff;color:#000;");
    ui->lineEdit_z->setStyleSheet("background-color:#fff;color:#000;");

    ui->pushButton_clear->setStyleSheet("background-color:#fdfdfd;color:#000;");
    ui->pushButton_noclear->setStyleSheet("background-color:#fdfdfd;color:#000;");
    ui->pushButton_light->setStyleSheet("background-color:#fdfdfd;color:#000;");
    ui->pushButton_dark->setStyleSheet("background-color:#fdfdfd;color:#000;");

    ui->label->setStyleSheet("color:#000;");
    ui->label_m->setStyleSheet("color:#000;");
    ui->label_z->setStyleSheet("color:#000;");
}

void Widget::on_pushButton_dark_clicked()
{
    //设置窗口为黑色
    this->setStyleSheet("background-color:#333;");

    ui->lineEdit_m->setStyleSheet("background-color:#333;color:#fff;");
    ui->lineEdit_z->setStyleSheet("background-color:#333;color:#fff;");

    ui->pushButton_clear->setStyleSheet("color:#fff;");
    ui->pushButton_noclear->setStyleSheet("color:#fff;");
    ui->pushButton_light->setStyleSheet("color:#fff;");
    ui->pushButton_dark->setStyleSheet("color:#fff;");

    ui->label->setStyleSheet("color:#fff;");
    ui->label_m->setStyleSheet("color:#fff;");
    ui->label_z->setStyleSheet("color:#fff;");
}
